package com.sgb.merchant.view.adapter;

import android.text.TextUtils;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.link.entity.merchant.DemandListEntity;
import com.sgb.merchant.BR;
import com.sgb.merchant.R;

import java.util.List;

public class SelfDemandListAdapter extends BaseQuickAdapter<DemandListEntity, BaseViewHolder> {

    public ClickBtnListener clickBtnListener;

    public void setClickBtnListener(ClickBtnListener clickBtnListener) {
        this.clickBtnListener = clickBtnListener;
    }
    public SelfDemandListAdapter(@Nullable @org.jetbrains.annotations.Nullable List<DemandListEntity> data) {
        super(R.layout.merchant_self_investment_demand,data);
    }

    @Override
    protected void convert(BaseViewHolder holder, DemandListEntity item) {
        ViewDataBinding binding = DataBindingUtil.bind(holder.itemView);
        binding.setVariable(BR.viewModel,item);
        holder.getView(R.id.tv_edit).setOnClickListener(v -> {
            if (clickBtnListener != null)
                clickBtnListener.editClick(item.getNo(), holder.getLayoutPosition());
        });
        holder.getView(R.id.tv_del).setOnClickListener(v -> {
            if (clickBtnListener != null)
                clickBtnListener.delClick(item.getNo(), holder.getLayoutPosition());
        });
        holder.getView(R.id.tv_item_put_away).setOnClickListener(v -> {
            if (clickBtnListener != null)
                clickBtnListener.putAway(item.getNo(), holder.getLayoutPosition());
        });
        holder.getView(R.id.tv_item_down_away).setOnClickListener(v -> {
            if (clickBtnListener != null)
                clickBtnListener.dowAway(item.getNo(), holder.getLayoutPosition());
        });
        if(!TextUtils.isEmpty(item.getDemandStatus())) {
            holder.setVisible(R.id.rl_btn,true);
            switch (item.getDemandStatus()) {//0 下架 1上架
                case "0":
                    holder.setImageResource(R.id.iv_state, R.mipmap.merchant_img_downaway)
                            .setVisible(R.id.tv_item_down_away, false)
                            .setVisible(R.id.tv_edit, true)
                            .setVisible(R.id.tv_item_put_away, true)
                            .setVisible(R.id.tv_del, true);
                    break;
                case "1":
                    holder.setImageResource(R.id.iv_state, R.mipmap.merchant_img_putaway)
                            .setVisible(R.id.tv_item_down_away, true)
                            .setVisible(R.id.tv_edit, false)
                            .setVisible(R.id.tv_item_put_away, false)
                            .setVisible(R.id.tv_del, false);
                    break;
            }
        }


    }
    public interface ClickBtnListener {
        void putAway(String no, int position);

        void dowAway(String no, int position);

        void editClick(String no, int position);

        void delClick(String no, int position);
    }
}
